package demo1;

/**
 * @Auther: 杨通通
 * @Date: 2024/10/22 08:19
 * @Description:
 */
public class threadlocal1 {
    private static final ThreadLocal<Integer> threadLocalValue = ThreadLocal.withInitial(() -> 0);
    public static void main(String[] args) throws InterruptedException {
        ThreadLocal<String> l1 =  ThreadLocal.withInitial(()->{
            return "default";
        });


        ThreadLocal<String> l2 = new ThreadLocal<>();

        l1.set("ytt");
        l2.set("ye");
        System.out.println(l1.get());
        new Thread(()->{
            l1.set("c1");
            System.out.println(l1.get());
        }).start();

        new Thread(()->{
            System.out.println(l1.get());
        }).start();
        Thread.sleep(100);
    }
}